package com.top.art.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.top.art.annotation.PermissionLimit;
import com.top.art.bo.ExaminationBO;
import com.top.art.bo.ExaminationPaperPageBO;
import com.top.art.entity.ExamineeInfo;
import com.top.art.service.IExamineeInfoService;
import com.top.art.vo.PaperQueryVO;
import com.top.art.vo.ProvinceVO;
import com.top.art.vo.ResVO;
import com.top.art.vo.ScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 考生信息表 前端控制器
 * </p>
 *
 * @author hjh
 * @since 2020-10-05
 */
@RestController
@RequestMapping("/examinee")
public class ExamineeInfoController {

    @Autowired
    private IExamineeInfoService examineeInfoService;

    @RequestMapping("/listByStudioCode")
    @PermissionLimit(limit = false)
    public ResVO listByStudioCode(@RequestBody ExaminationPaperPageBO bo) {
        IPage<ExamineeInfo> page = examineeInfoService.page(bo);
        return new ResVO<>(page);
    }

    @RequestMapping("/listExamineeInfo")
    @PermissionLimit(limit = false)
    public ResVO<Page<ExamineeInfo>> listExamineeInfo(@RequestBody ExaminationBO bo) {
        IPage<ExamineeInfo> infoPage = examineeInfoService.listExamineeInfo(bo);
        Page<ExamineeInfo> page = new Page<>(bo.getCurrent(), bo.getSize());
        page.setTotal(infoPage.getTotal());
        page.setRecords(infoPage.getRecords());
        return new ResVO<>(page);
    }

    @GetMapping(value = "/listProvince")
    @PermissionLimit(limit = false)
    public ResVO<List<ProvinceVO>> listProvince() {
        return new ResVO<>(examineeInfoService.queryProvince());
    }


    @GetMapping(value = "/queryExamineeCount")
    @PermissionLimit(limit = false)
    public ResVO queryExamineeCount(String studioCount) {
        return new ResVO(examineeInfoService.count(Wrappers.<ExamineeInfo>lambdaQuery().eq(ExamineeInfo::getStudioCode, studioCount)));
    }

    @RequestMapping("/list")
    @PermissionLimit(limit = false)
    public ResVO list(@RequestBody ExaminationPaperPageBO bo) {
        IPage<ExamineeInfo> page = examineeInfoService.page(bo);
        return new ResVO<>(page);
    }

    @PostMapping(value = "/checkIdAndTicketCode")
    @PermissionLimit(limit = false)
    public ResVO checkIdAndTicketCode(@RequestBody ExamineeInfo ei) {
        return new ResVO(examineeInfoService.checkIdAndTicketCode(ei));
    }
}
